# clean environment
rm(list=ls())

# load packages
library(ggplot2)

# load data set with parliamentary inquiries
dat <- read.csv("inquiries.csv")

# create filler variable to sum over
dat$one <- 1

# aggregate number of inquiries by jurisdiction and year
dat_agg <- aggregate(one~jurisdiction+year, dat, sum)

# write out jurisdiction name
dat_agg$jurisdiction2 <- NA
dat_agg$jurisdiction2[dat_agg$jurisdiction=="bb"] <- "Brandenburg"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="be"] <- "Berlin"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="bt"] <- "Federal"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="bw"] <- "Baden-Wuerttemberg"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="by"] <- "Bavaria"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="hb"] <- "Bremen"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="he"] <- "Hessen"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="hh"] <- "Hamburg"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="mv"] <- "Mecklenburg-Vorpommern"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="ni"] <- "Niedersachsen"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="nw"] <- "North Rhine-Westphalia"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="rp"] <- "Rheinland-Pfalz"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="sh"] <- "Schleswig-Holstein"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="sl"] <- "Saarland"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="sn"] <- "Saxony"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="st"] <- "Saxony-Anhalt"
dat_agg$jurisdiction2[dat_agg$jurisdiction=="th"] <- "Thuringia"

# turn jurisdiction into factor variable
dat_agg$jurisdiction2 <- factor(dat_agg$jurisdiction2)
dat_agg$jurisdiction2 <- factor(dat_agg$jurisdiction2, levels=rev(levels(dat_agg$jurisdiction2)))

# figure
ggplot(data=dat_agg, aes(x=jurisdiction2, y=year, color=one)) + 
  coord_flip() + 
  geom_point() +
  theme_classic() +
  theme(legend.position = "bottom", text=element_text(size=14), axis.text.x = element_text(angle = -90)) +
  scale_colour_gradient(low="grey", high="black", name="N") +
  xlab("") + ylab("") +
  scale_y_continuous(limits=c(1950, 2020), breaks=seq(1950, 2020, 10)) 

ggsave("FigC1.pdf", width=7, height=5)
